package com.example.shop.fgo.task.upload.controller;

import android.os.Environment;

import com.example.shop.fgo.task.upload.model.SDEntity;

import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * Created by Administrator on 2017/2/26.
 */

public class GetSDEntityUtil {
    
    public static List<SDEntity> getDir(String parentPath){
        File fileParent=new File(parentPath);
        File[] files = fileParent.listFiles();
        
        List<SDEntity> sdEntities=new ArrayList<>();
        for (File file : files) {
            SDEntity sdEntity=new SDEntity();
            sdEntity.setDir(file.isDirectory());
            sdEntity.setName(file.getName());
            sdEntity.setSize(file.length());
            sdEntity.setAbsolutePath(file.getAbsolutePath());
            if (file.isFile()&&file.getName().contains(".")){
                //aa.mp3
                sdEntity.setIco(file.getName().substring(file.getName().lastIndexOf(".")+1));
            }

            sdEntities.add(sdEntity);
            
        }
        Collections.sort(sdEntities);
        return sdEntities;
        
    
    }
    
    public static List<SDEntity> getRootSD(){
        return getDir(Environment.getExternalStorageDirectory().getAbsolutePath());
    }
}
